import { withI18n, useI18n, getRequestLanguage } from "../i18n";
import React from "react";
import { GetServerSideProps } from "next";
import ErrorPage from "./_error";

interface IErrorProps {
    /**
     * 错误信息
     */
    error: {
        [key: string]: any;
    };
}

export default withI18n<IErrorProps>(({ error }) => {
    const { lang } = useI18n();
    return <ErrorPage {...error} lang={lang} />;
});

export const getServerSideProps: GetServerSideProps<IErrorProps> = async ({ req, query }) => {
    const requestLanguage = getRequestLanguage(req);

    return {
        props: {
            lang: requestLanguage,
            error: query,
        },
    };
};
